Repository navigation
Conversation
These tests fail on main. A socket opened with a token that carries no session is never closed when that token expires or when its user is deleted, the handshake never stamps the token expiry, and the UI never retries a server close.
… delete A socket accepted on a token that carries no session now keeps the token's exp, stamped by the handshake on both transports. The sweep closes it at its first pass after exp and sends tokenExpiredChannel first. Deleting a user closes all of that user's sockets on this server and tells the peers, and the sweep also closes the sockets of a user who no longer exists, which covers peers without Redis.
…expired The server now sends tokenExpiredChannel right before it closes a socket opened without a session at its token's exp. The UI retries only that close, with the token it holds now, which it renewed before exp. Every other server close stays final.
…gn doc Adds the decision record for sockets without a session, amends the record on push feed handshakes to say that trust in such a token lasts until its exp, and updates the multi node session design to match.
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
|
Local test results for this PR. PR CI runs only the Java unit tests, so the integration tests below were run on my machine. Unit tests, on the test commit before the fix (red)
Jest, Integration tests on the test commit (MySQL and Elasticsearch, global state lane), only the new ones:
With the fix (green) Unit tests, on the fix: Jest, Integration tests on the fix, first pass:
One more caveat about that first pass: a test harness class compiled from an early draft of mine (which I dropped before the first commit) set the server's sweep interval to 15 s, so the red run and this first pass swept every 15 s instead of 60 s (that only shortened the red waits). Sweeping more often is the stricter case for "does not close the wrong sockets", but CI runs at 60 s, so the second pass recompiles the harness and runs at the default. Integration tests on the fix, second pass (MySQL and Elasticsearch, global state lane, harness recompiled, server at the default 60 s sweep, no multi node suite in the fork): In total on the fix: PF 01 also asserts the order the client saw: One thing the multi node case cannot show: the nodes of the in process test cluster share one push feed socket registry, so that test proves the close across the nodes' endpoints, but not the sweep on a peer without Redis. That path is covered by Other checks
|
Code Review ✅ Approved 🔴 High riskEnforcing token expiry and user deletion for sessionless push-feed sockets changes ongoing access control; missed revocation could leave deleted users receiving feed data. Closes push feed sockets opened without a session once their token expires or their user is deleted, via a VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
Describe your changes:
Fixes #38245
A push feed socket opened with a token that carries no session (a public client SSO provider token, a bot token, a personal access token) was trusted on that token's validation, once, at the upgrade, and never checked again. It stayed open after the token expired and after its user was deleted, until the client left or the server restarted.
Root cause (lines on main at 1971feb):
SocketAddressFilter.validateCookielessHandshakeaccepts such a handshake on the token alone (SocketAddressFilter.java:269), andvalidatePrefixedTokenRequest(:313) keeps only the user name and session claim from the verified claims. Theexpis thrown away.HandshakeIdentity(HandshakeIdentity.java:23) had nowhere to carry an expiry, so nothing about it reached the socket on either transport.WebSocketManager.disconnectInactiveSessions(WebSocketManager.java:307), looks only at sockets with a session id (:319), so it skipped these sockets entirely.OpenMetadataApplication.wireSessionRevocationToWebSockets,:1216, publishing at:1232). Deleting a user goes throughUserRepository.revokeLiveSessions(UserRepository.java:1839) andSessionService.revokeSessionsForUser(SessionService.java:738), which finds zero sessions for a user who signed in with a provider token, so none of their sockets closed.disconnectAllForUser(WebSocketManager.java:250) existed, and peers already answer a revoke without a session id with it (CacheBundle.java:125), but nothing published one.WebSocketProvider.tsx:128). Polling requests go through the filter on every request and get a 401 once the token expires.The fix
expand stamps it as a server ownedTokenExpiresAtheader (epoch milliseconds), on both transports, only when it accepted the socket without a session. A client's own copy of that header is always dropped. A socket with a session is still governed by its session, which the sweep already rechecks.exp, using the same strict comparison and zero leeway asJwtFilter. Right before closing it sendstokenExpiredChannelto that socket. A stamped value the server cannot read counts as expired.UserRepository.beginDeleteLifecycleclosure, which every delete path runs (including the bulk soft delete of a bot's user that skipspostDelete), callsWebSocketManager.endAccessForUser. That closes the user's sockets on this server and publishessession/revokewith the user id and no session id, which peers on main already handle.PushFeedUserPresence, a cached lookup) and closes all their sockets if not. A failed lookup is not a deletion: the sockets stay and the next pass asks again. This covers peers without Redis, tokens with noexp, and a handshake validated just before the delete that registers after it.WebSocketProviderretries a server close only whentokenExpiredChannelcame first, reading the current token (the app renews it about 60 s beforeexp). Every other server close is still final, so the rule in the ADR "A refresh ends sessions issued by a provider that is no longer configured" holds. Without this, every public client SSO tab would lose push once per provider token lifetime.CacheInvalidationPubSubgetsTYPE_SESSIONandOP_REVOKEconstants;CacheBundleand the revocation listener use them. No behavior change there.Bound: a socket without a session closes at most one sweep interval after
exp(60 s by default, 15 s at least,WEBSOCKET_SESSION_VALIDATION_INTERVAL_SECONDS). After a user delete it closes at once on the server that ran the delete and on Redis peers, and within one interval plus the 30 s entity cache on peers without Redis.Unchanged on purpose: sockets with a session are not bounded by their access token's
exp(basic and confidential tabs would drop every hour). Tokens withoutexp(an Unlimited bot token or personal access token) get no expiry bound, the same as on REST; deletion, a provider switch and a restart still end them.isSessionActiveForUserkeeps its predicate, which is what #38247 changes.No tokens are logged. The new close logs carry only the user id and socket id.
Type of change:
High level design:
Approach. Reuse the sweep that already runs every interval rather than adding a timer per socket. The expiry is stamped where the identity is already stamped (
SocketAddressFilter.stampIdentityfor polling,Jetty12WebSocketHandler.stampValidatedIdentityfor the upgrade); the header names now live once onHandshakeIdentity.WebSocketManagertakes aPushFeedSocketPolicy(the applied provider, a clock, the user presence check and the peer notifier); the existing builder overloads stay and default to "no user is gone, no peer is told". The per socket expiry lives inSocketTokenExpiries, one entry per registered socket, removed on every disconnect path through oneforgetSocket. It is a registry bounded by live connections, not a cache, so the cache size rule in AGENTS.md does not apply.Alternatives rejected.
exp: a new executor and cancellation bookkeeping, and pending tasks for 90 day tokens. The sweep bound matches the staleness the multi node design already accepts.postDelete: the bulk bot user delete skips it.revokeSessionsForUser: a password change also calls it, and personal access token and bot sockets must survive that.Compatibility and rollout.
exp, is disconnected up to one interval afterexp. Public client SSO tabs reconnect on their own thanks to the UI change; other clients must reconnect aftertokenExpiredChannel. Deleted users lose their sockets at once.HandshakeIdentityconstructor, bothWebSocketManagerBuilder.buildoverloads,validatePrefixedTokenRequest,disconnectInactiveSessions). I could not grep the Collate repository from here, so a Collate check forHandshakeIdentity(andWebSocketManagerBuilder.buildis still worth doing.Decision records. New ADR "A push feed socket without a session ends when its token expires or its user is deleted", and a v2 amendment to "Push feed socket handshakes are always authenticated" saying that trust in a token without a session lasts until its
exp. The multi node session design doc (sections 8.2, 8.3, 8.4, 10.3 and 11) is updated to match.Tests:
Use cases covered
tokenExpiredChannelfirst, and another user's socket with a valid token stays open.These tests fail on main (run against the test commit, before the fix):
WebSocketManagerTest:disconnectInactiveSessions_closesASessionlessSocketOnceItsTokenHasExpired,disconnectInactiveSessions_sendsTheTokenExpiredNoticeBeforeClosing,onConnection_treatsAMalformedExpiryAsExpiredOpenMetadataApplicationAuthReloadTest.buildPushFeedSockets_closesEverySocketOfAUserWhoIsGoneSocketAddressFilterTest:providerTokenHandshakeWithoutSessionIsStampedWithItsExpiry,clientSentTokenExpiresAtHeaderIsDropped,upgradeHandlerStampsTheValidatedExpiryAndDropsTheClientsCopyJetty12WebSocketHandlerTest.clientTokenExpiryHeaderIsDroppedBeforeStampingWebSocketProvider.test.tsx: the reconnect after the token expired notice, and the single retry per noticeSsoPushFeedSocketITandSessionMultiNodeIT.pushFeedSocketOpenedWithAPersonalAccessTokenClosesWhenItsUserIsDeletedOnAnotherNode(see the results comment)The tests that need the new API (the hand moved clock cases,
endAccessForUser,PushFeedUserPresenceTest,publishUserAccessEnded) are in the fix commit, since they cannot compile on main.Unit tests
I added unit tests for the new and changed logic.
Files added or updated:
WebSocketManagerTest,SocketAddressFilterTest,Jetty12WebSocketHandlerTest,PushFeedUserPresenceTest(new),OpenMetadataApplicationAuthReloadTest,WebSocketProvider.test.tsx. The clock tests use a hand movedClock, no sleeps.Coverage from the unit run (jacoco, with the static code analysis profile):
PushFeedUserPresence,PushFeedSocketPolicy,SocketTokenExpiriesandHandshakeIdentity100%,SocketAddressFilter94%,WebSocketManager88% overall. Of the lines this PR changes inWebSocketManager,SocketAddressFilterandJetty12WebSocketHandler, all are covered except the twoconnect_errorandconnect_failedlog lambdas that moved unchanged intolistenForClose. The uncovered lines elsewhere inWebSocketManagerandJetty12WebSocketHandlerare untouched relay and transport code. TheUserRepositoryhook is covered bySsoPushFeedSocketIT.Backend integration tests
SsoPushFeedSocketIT(new),SessionMultiNodeIT(one new method),PushFeedSocket(new helper, a socket.io client opened the way the UI opens one),MockOidcProviderandMockOidcTokens(an ID token with a chosen lifetime).*Sso*ITand*Feed*ITpatterns andsocket/**is already owned, so the impact map needed no change (the branch check in the local test planner is clean).Ingestion integration tests
Playwright (UI) tests
WebSocketProvider, covered by its Jest test; nothing on screen changes.Manual testing performed
SsoPushFeedSocketITand the newSessionMultiNodeITmethod against the test commit to see them fail, then the IT scope in the PR comment against the fix.UI screen recording:
Not applicable: this is a bug fix with no visible UI change. The UI part only decides whether to reconnect a socket after one specific server close.
Checklist:
Fixes #38245: <short explanation>Fixes #38245above.Related
SocketAddressFilter.authenticateandJetty12WebSocketHandlerstamps the validated identity. I think it can be closed with a pointer to fix(socket): validate credentials on push-feed WebSocket handshakes under all configurations #36143.isSessionActiveForUserand its predicate as they are; whichever PR merges second rebasesdisconnectInactiveSessions.